<?php
//require_once("qiniu/io.php");
//require_once("qiniu/rs.php");
//require_once("qiniu/fop.php");
//$bucket = "icecream";
//$accessKey = 'Ae9rYKWUhPBh6oUBlxh5V_--sxntgz6bhWENqlzQ';
//$secretKey = '7vSE5Uzd0sWqdkqyCXyzjn-1tV2mSotkaEoZ9TqM';
//Qiniu_SetKeys($accessKey, $secretKey);
//$putPolicy = new Qiniu_RS_PutPolicy($bucket);
//$upToken = $putPolicy->Token(null);
//$qiniuurl = 'http://icecream-10003474.image.myqcloud.com/';
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type='text/javascript' src='js/jquery.min.js'></script>
    <script type="text/javascript" src="js/plupload/plupload.full.min.js"></script>
</head>
<body>
<div id="uploader">
    <button id="upFiles">点击上传</button>
</div>
<div id="upImgBox"></div>
<script>
    var upToken = "<?php echo $upToken; ?>";
    var picName = "<?php echo date('Ymd_His');?>";
    var uploader = new plupload.Uploader({
        browse_button : 'upFiles',
        runtimes : 'html5,flash,silverlight,html4',
        url : 'http://www.weizhile.cn/qq.php',
        container: document.getElementById('uploader'),
        flash_swf_url : 'js/plupload/Moxie.swf',
        silverlight_xap_url : 'js/plupload/Moxie.xap',
        unique_names : true,
        resize : { width : 1500, height : 1500, quality : 90 },
        filters : {
            max_file_size : '2mb',
            mime_types: [
                {title : "Image files", extensions : "jpg,jpeg,gif,png,svg"}

            ]
        },

        init: {
            PostInit: function() {},
            BeforeUpload:function(up,file){
                uploader.setOption("multipart_params",{
                    'token': upToken,
                    'file': file,
                    'key': picName + file.id
                });
            },
            FilesAdded: function(up, files) {
                plupload.each(files, function(file) {
                    $('#upImgBox').prepend('<div id="' + file.id + '" class="elementImgBox f_l"><div class="elementImgEl">等待...</div></div>');
                });
            },
            QueueChanged:function(up, files){
                uploader.start();
            },
            UploadProgress: function(up, file) {
                document.getElementById(file.id).innerHTML = '<div class="elementImgEl">' + file.percent + "%</div>";
                if(file.percent==100){
                    document.getElementById(file.id).innerHTML = '<div class="elementImgEl">即将完成</div>';
                }
            },
            UploadComplete: function(up, files) {

            },
            FileUploaded:function(up, file, res){
//                $('#'+file.id).remove();
                document.getElementById(file.id).innerHTML = '<div class="elementImgEl"><img src="http://icecream-10003474.image.myqcloud.com/'+picName+file.id+'" alt=""/></div>';
            },
            Error : function(up, err) {
                alert("此文件文件过大或格式不支持！");
                $('#'+file.id).remove();
            }
        }

    });
    uploader.init();
</script>
</body>
</html>